{% extends "base.html" %}
{% block title %}任务列表{% endblock %}
{% block user %}任务列表{% endblock %}
{% block navbar %}{{ super() }}{% endblock %}
{% block styles %}{{ super() }}
<style>
    .main-div {
        background: #ffffff none repeat scroll 0 0;
        border-radius: 2px;
        margin: 10px auto 30px;
        max-width: 80%;
        padding: 20px 20px 20px 20px;
    }

    body {
        padding-top: 100px;
    }

    /* .fc-time {
        display: none;
    } */
</style>
<link href="{{ url_for("static", filename="css/dashboard.css") }}" rel="stylesheet">
{% endblock %}

{% block scripts %}{{ super() }}

<script>
    holidays = JSON.parse({{ holidays | tojson | safe }});
    holidaysOffset = JSON.parse({{ holidaysOffset | tojson | safe }});
</script>
<script>
    $(function () {
        function getHolidayEvents(holidays, color) {
            var events = [];
            for (var key in holidays) {
                events.push(
                    {
                        "color": color,
                        "start": key,
                        "manhour": 0,
                        "remark": '',
                        "title": '_' + holidays[key] + '_'
                    }
                );
            }
            return events;
        }

        $('#calendar').fullCalendar({
            header: {
                left: 'prev,today,next',
                center: 'title',
                right: 'basicWeek,basicDay,month,listMonth'
            },

            listDayAltFormat: false,
            firstDay: 1,
            locale: 'zh-cn',
            showNonCurrentDates: false,
            buttonIcons: false,
            editable: false,
            draggable: false,
            weekNumbers: true,
            navLinks: false,
            selectable: true,
            selectHelper: false,
            eventLimit: true,
            eventTextColor: '#000000',

            displayEventTime: false,
            eventSources: [
                // 假日
                {
                    events: getHolidayEvents(holidays, "#f31cdc")
                },
                // 补班
                {
                    events: getHolidayEvents(holidaysOffset, "#23dd1c")
                },
                // 分配的任务
                {
                {% if receiver_name %}
                    url: 'ajax?user=receiver',
            {% else %}
                    url: 'ajax?user=sender',
        {% endif %}
        error: function () {
            $('#script-warning').show();
        }
            }
        ]
    });
});
</script>

<script>
    $(document).ready(function () {
        $('#dt').DataTable(
            {
                "autoWidth": true,
                "pageLength": 25,
                dom: '<"top"flipB<"clear">>rt<"bottom"ipB<"clear">>',
                "order": [[8, "desc"]]
            });
    });
</script>
{% endblock %}
{% block content %}
<div class="container">
    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            {% include 'flash_message.html' %}

            <h2 class="row page-header">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" style="text-align:left">
                    {% if receiver_name %}
                    {{ receiver_name }} 收到的任务
                    <a class="btn btn-info" href="{{ url_for('bp_partner.calendar', user_id=receiver_id) }}">查看他的日历
                        <span class="glyphicon glyphicon-calendar" aria-hidden="true"></span>
                    </a>
                    <a class="btn btn-warning" href="{{ url_for('bp_partner.assign', user_id=receiver_id) }}">给他分配任务
                        &#x1f4b0</a>
                    <a class="btn btn-danger" href="{{ url_for('bp_partner.send', user_id=receiver_id) }}">他发出的任务
                        &#x1f4E4</a>
                    {% else %}
                    {{ sender_name }} 发出的任务
                    <a class="btn btn-info" href="{{ url_for('bp_partner.calendar', user_id=sender_id) }}">查看他的日历
                        <span class="glyphicon glyphicon-calendar" aria-hidden="true"></span>
                    </a>
                    <a class="btn btn-warning" href="{{ url_for('bp_partner.assign', user_id=sender_id) }}">给他分配任务
                        &#x1f4b0</a>
                    <a class="btn btn-success" href="{{ url_for('bp_partner.receive', user_id=sender_id) }}">他收到的任务
                        &#x1f4e5</a>

                    {% endif %}
                </div>

                </p>
            </h2>
            <table id="dt" class="row-border hover compact" style="width:100%">
                <thead>
                    <tr>
                        <th>工作令号</th>
                        <th>项目名称</th>
                        <th>
                            {% if receiver_name %}
                            发起人
                            {% else %}
                            接收人
                            {% endif %}
                        </th>
                        <th>任务摘要</th>
                        <th>任务明细</th>
                        <th>开始时间</th>
                        <th>结束时间</th>
                        <th>任务权重</th>
                        <th>创建时间</th>
                        <th>修改时间</th>
                        <th>是否完成</th>
                        {% if receiver_name %}
                        {% if receiver_id == current_user.id %}
                        <th>编辑</th>
                        {% endif %}
                        {% endif %}
                        <th>分数</th>
                        {% if sender_name %}
                        {% if sender_id == current_user.id %}
                        <th>操作</th>
                        <th>操作</th>
                        <th>操作</th>
                        <th>操作</th>
                        {% endif %}
                        {% endif %}
                    </tr>
                </thead>
                <tbody>
                    {% for assignment in assignments %}
                    <tr>
                        <td>{{ assignment[9] }}</td>
                        <td>{{ assignment[10] }}</td>

                        {% if sender_id %}
                        <td><a
                                href="{{ url_for('bp_partner.receive', user_id=assignment.receiver_id) }}">{{ assignment[8] }}</a>
                        </td>
                        {% else %}
                        <td><a
                                href="{{ url_for('bp_partner.send', user_id=assignment.sender_id) }}">{{ assignment[8] }}</a>
                        </td>
                        {% endif %}

                        <td><a
                                href="{{ url_for('bp_partner.view', assignment_id=assignment[0]) }}">{{ assignment[1] }}</a>
                        </td>
                        <td>{{ assignment[2] }}</td>
                        <td>{{ assignment[3] }}</td>
                        <td>{{ assignment[4] }}</td>
                        <td>{{ assignment[5] }}</td>
                        <td>{{ assignment[6] }}</td>
                        <td>{{ assignment[13] }}</td>
                        <td>
                            {% if assignment[11] %}
                            <span class="glyphicon glyphicon-check" aria-hidden="true"></span>
                            {% else %}
                            <span class="glyphicon glyphicon-unchecked" aria-hidden="true"></span>
                            {% endif %}
                        </td>
                        {% if receiver_name %}
                        {% if receiver_id == current_user.id %}
                        {% if assignment[11] %}
                        <td><a href="{{ url_for('bp_partner.unfinish', assignment_id=assignment[0]) }}">标记未完成</a></td>
                        {% else %}
                        <td><a href="{{ url_for('bp_partner.finish', assignment_id=assignment[0]) }}">标记完成</a></td>
                        {% endif %}
                        {% endif %}
                        {% endif %}

                        {% if assignment[12] %}
                        <td>{{ assignment[12].__int__() }}</td>
                        {% else %}
                        <td>0</td>
                        {% endif %}

                        {% if sender_name %}
                        {% if sender_id == current_user.id %}
                        {% if assignment[12] %}
                        <td><a href="{{ url_for('bp_partner.grade', assignment_id=assignment[0]) }}">修改</a></td>
                        {% else %}
                        <td><a href="{{ url_for('bp_partner.grade', assignment_id=assignment[0]) }}">打分</a></td>
                        {% endif %}
                        <td><a href="{{ url_for('bp_partner.edit', assignment_id=assignment[0]) }}">编辑</a></td>
                        <td><a href="{{ url_for('bp_partner.attachment', assignment_id=assignment[0]) }}">上传附件</a></td>
                        <td><a href="{{ url_for('bp_partner.delete', assignment_id=assignment[0]) }}">删除</a></td>
                        {% endif %}
                        {% endif %}



                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>


<div class="container">
    <h2 class="row page-header">
        <p class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            {% if receiver_name %}
            {{ receiver_name }} 收到的任务日历
            {% else %}
            {{ sender_name }} 发出的任务日历
            {% endif %}
            （绿色为已完成）
        </p>
    </h2>
    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-center-block">
            <div>
                <div id='calendar'></div>
            </div>
        </div>
    </div>
</div>
{% endblock %}